//
//  ChangeSexViewController.m
//  CommunityApp
//
//  Created by 秦乾龙 on 16/12/14.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "ChangeSexViewController.h"
#import "AFNetworking.h"//主要用于网络请求方法
#import "UIKit+AFNetworking.h"//里面有异步加载图片的方法
#import "AFHTTPSessionManager.h"
#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#import "NavView.h"
#import "ZYButton.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScale   ([UIScreen mainScreen].bounds.size.width)/750
@interface ChangeSexViewController ()
@property (nonatomic,retain)ZYButton*manBtn;
@property (nonatomic,retain)ZYButton*woManBtn;
@property (nonatomic,retain)ZYButton*selectBtn;
@property (nonatomic,retain)NSString*sexStr;

@end

@implementation ChangeSexViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.titleView = [ViewFactory makeNavigationTitle:@"修改性别"];
    
    UIBarButtonItem *backBtn = [ViewFactory makeNavigationBackWhite:self action:@selector(backClick)];
    self.navigationItem.leftBarButtonItem = backBtn;
    UIButton *buttonNotice = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonNotice.frame = CGRectMake(0, 0, 40, 20);
    buttonNotice.titleLabel.font = [UIFont systemFontOfSize:15];
    [buttonNotice setTitle:@"确定" forState:UIControlStateNormal];
    
    UIBarButtonItem *btnNoticeItem = [[UIBarButtonItem alloc]initWithCustomView:buttonNotice];
    [buttonNotice addTarget:self action:@selector(changeClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = btnNoticeItem;
    
    self.view.backgroundColor = [UIColor colorWithRed:32/255.0 green:32/255.0 blue:32/255.0 alpha:1.0f];
    UIView *backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
    backgroundView.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0f];
    [self.view addSubview:backgroundView];
    
    if (_user.sex)
    {
        _sexStr = _user.sex;
    }
    else
    {
        _sexStr = @"00";
    }
    _sexStr = _user.sex;
    _manBtn = [ZYButton buttonWithType:UIButtonTypeCustom];
    _manBtn.frame = CGRectMake(0, 0, kScreenW, 100*kScale);
    [_manBtn addTarget:self action:@selector(selectClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_manBtn];
    UILabel *sexLable = [[UILabel alloc]initWithFrame:CGRectMake(30*kScale, 0, 50*kScale, 100*kScale)];
    sexLable.text = @"男";
    
    _manBtn.tag = 10;
    [_manBtn addSubview:sexLable];
    UIImageView *boolSelectView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"选中"]];
    boolSelectView.frame = CGRectMake(kScreenW-80*kScale, 36*kScale, 41*kScale, 28*kScale);
    boolSelectView.hidden = YES;
        _manBtn.boolSealect = boolSelectView;
        [_manBtn addSubview:boolSelectView];
    _woManBtn = [ZYButton buttonWithType:UIButtonTypeCustom];
    _woManBtn.frame = CGRectMake(0, 102*kScale, kScreenW, 100*kScale);
    [_woManBtn addTarget:self action:@selector(selectClick:) forControlEvents:UIControlEventTouchUpInside];
    _woManBtn.tag = 11;
    [self.view addSubview:_woManBtn];
    UILabel *sexLable2 = [[UILabel alloc]initWithFrame:CGRectMake(30*kScale, 0, 50*kScale, 100*kScale)];
    
    sexLable2.text = @"女";


    [_woManBtn addSubview:sexLable2];
    UIImageView *boolSelectView2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"选中"]];
    boolSelectView2.frame = CGRectMake(kScreenW-80*kScale, 36*kScale, 41*kScale, 28*kScale);
    boolSelectView2.hidden = YES;
    
    _woManBtn.boolSealect = boolSelectView2;
    [_woManBtn addSubview:boolSelectView2];
    if ([_sexStr isEqual:[NSNull null]]||[_sexStr isEqualToString:@"00"])
    {
        _selectBtn = _manBtn;
    }
    else
    {
        _selectBtn = _woManBtn;
    }
    _selectBtn.boolSealect.hidden = NO;
}
- (void)selectClick:(ZYButton*)sender
{
    if (sender.tag==10)
    {
        _sexStr = @"00";
    }
    else if (sender.tag==11)
    {
        _sexStr = @"01";
    }
    _selectBtn.boolSealect.hidden = YES;
    _selectBtn = sender;
    _selectBtn.boolSealect.hidden = NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)backClick
{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)changeClick
{
    [self request];
}
- (void)request
{
    NSString *urlStr = [[NSString stringWithFormat:@"%@/userCenter/modifyMemberUserGender?user_gender=%@",APIYIGOU,_sexStr]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    DYBaseRequest *request = [DYBaseRequest new];
    request.requestUrl = urlStr;
    [request dyBgStartWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *allDic = [NSDictionary changeType:request.responseJSONObject];
        NSLog(@"111%@",allDic);
        [self.navigationController popViewControllerAnimated:YES];
    } error:^(YTKBaseRequest *request) {
        
    } failure:^(YTKBaseRequest *request) {
        [ViewFactory showErrorStrMsg:NETWORK_ERR];
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
